#include "upordown.h"
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QSpacerItem>
#include <QListView>

UporDown::UporDown(QWidget *parent)
    : QWidget{parent}
{
    creat();

    connect(btn,SIGNAL(clicked(bool)),this,SLOT(btnSlots()));
}

UporDown::~UporDown()
{
    delete btn;
    btn = nullptr;

    delete line;
    line = nullptr;

    delete label;
    label = nullptr;
}
//升降：1：升    0：降
void UporDown::creat()
{
    btn = new QPushButton("确定");
    label = new QLabel("升降符号：");

    line = new QComboBox();
    QListView* listView1 = new QListView(this);
    line->setView(listView1);
    QStringList list;
    list<<"1"<<"0";
    line->addItems(list);

    QHBoxLayout *h_layout = new QHBoxLayout();
    QVBoxLayout *V_layout = new QVBoxLayout;

    QSpacerItem *h_spacer = new QSpacerItem(10,10,QSizePolicy::Expanding,QSizePolicy::Minimum);
    QSpacerItem *v_spacer = new QSpacerItem(10,10,QSizePolicy::Minimum,QSizePolicy::Expanding);

    h_layout->addItem(h_spacer);
    h_layout->addWidget(label);
    h_layout->addItem(h_spacer);
    h_layout->addWidget(line);
    h_layout->addItem(h_spacer);

    V_layout->addItem(v_spacer);
    V_layout->addLayout(h_layout);
    V_layout->addItem(v_spacer);
    V_layout->addWidget(btn);
    V_layout->addItem(v_spacer);

    setLayout(V_layout);
}

void UporDown::btnSlots()
{
    QString num = line->currentText();

    emit mysignalUporDown(num.toInt());
}
